const router = require('koa-router')();
const config = require('../config/config.local');

const getLowestOfferListings = require('./products/getLowestOfferListings');
const getMatchingProduct = require('./products/getMatchingProduct');
const getMyFeesEstimate = require('./products/getMyFeesEstimate');
const getMyPrice = require('./products/getMyPrice');
const listMatchingProducts = require('./products/listMatchingProducts');
const getLastUpdatedTimeForRecommendations = require('./recommendations/getLastUpdatedTimeForRecommendations');
const listRecommendations = require('./recommendations/listRecommendations');

router.use('', getLowestOfferListings.routes(), getLowestOfferListings.allowedMethods());
router.use('', getMatchingProduct.routes(), getMatchingProduct.allowedMethods());
router.use('', getMyFeesEstimate.routes(), getMyFeesEstimate.allowedMethods());
router.use('', getMyPrice.routes(), getMyPrice.allowedMethods());
router.use('', listMatchingProducts.routes(), listMatchingProducts.allowedMethods());
router.use('', getLastUpdatedTimeForRecommendations.routes(), getLastUpdatedTimeForRecommendations.allowedMethods());
router.use('', listRecommendations.routes(), listRecommendations.allowedMethods());

router.get('/', async (ctx, next) => {
  await ctx.render('index', {
    title: 'Hello Koa 2! from pt-core-market'
  })
});

router.get('/ver', async (ctx, next) => {
  const deploymentVersion = config.ver;
  ctx.body = `welcome, deployment version: ${deploymentVersion}`;
});

router.get('/string', async (ctx, next) => {
  ctx.body = 'koa2 string'
});

router.get('/json', async (ctx, next) => {
  ctx.body = {
    title: 'koa2 json'
  }
});

module.exports = router;
